﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

namespace NExt.Handler.Base.Default
{
    public class CompositeContentBuilder: IContentBuilder
    {
        private const string COMPOSITE_SCRIPT_SEPERATOR = "\r\n";
        private readonly IEnumerable<IContentBuilder> contentBuilders;

        public CompositeContentBuilder(params IContentBuilder[] contentBuilders)
        {
            this.contentBuilders = contentBuilders;
        }

        public CompositeContentBuilder(IEnumerable<IContentBuilder> contentBuilders)
        {
            this.contentBuilders = contentBuilders;
        }

        public string Build(HttpContext context)
        {
            StringBuilder stringBuilder = new StringBuilder();
            foreach (IContentBuilder contentBuilder in contentBuilders)
            {
                string content = contentBuilder.Build(context);
                stringBuilder.Append(COMPOSITE_SCRIPT_SEPERATOR);
                stringBuilder.Append(content);
            }
            return stringBuilder.ToString();
        }
    }
}
